package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_ProductMotifService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_ProductMotifController {
    @Autowired
    private Ad_ProductMotifService ad_productMotifService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adProductMotif", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductMotif(HttpServletRequest request, @RequestBody HoaTietDto productMotifDto) {
        return new JsonResponseDto<Integer>(ad_productMotifService.adminProductMotif(productMotifDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adProductMotifDelete", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductMotifDelete(HttpServletRequest request, @RequestBody List<HoaTietDto> productMotifDto) {
        return new JsonResponseDto<Integer>(ad_productMotifService.adminProductMotifDelete(productMotifDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllMotif", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaTietDto>> getAllMotif(HttpServletRequest request) {
        return new JsonResponseDto<List<HoaTietDto>>(ad_productMotifService.getAllMotif(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductMotifPage/{maHoaTiet}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageProductMotif(HttpServletRequest request, @PathVariable String maHoaTiet, Map<String, Object> map) throws ParseException {
        map.put("maHoaTiet", maHoaTiet);
        return new ModelAndView("admin/ad-product-motif-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editProductMotif", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<HoaTietDto> getMotifInfoEdit(HttpServletRequest request, @RequestBody HoaTietDto motifDto) {
        return new JsonResponseDto<HoaTietDto>(ad_productMotifService.getMotifInfoEdit(motifDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerMotifEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<HoaTietDto> registerMotifEdit(HttpServletRequest request, @RequestBody HoaTietDto motifDto) {
        return new JsonResponseDto<HoaTietDto>(ad_productMotifService.registerMotifEdit(motifDto), JsonResponseCode.SUCCESS);
    }
}
